<template>
  <el-row type="flex" justify="space-around" align="middle" style="height: 40px;width:100%">
    <el-col><span>{{ treeNode.name }}</span></el-col>
    <el-col :span="4">
      <el-row type="flex" justify="end">
        <el-col>{{ treeNode.manager }}</el-col>
        <!-- 下拉菜单 -->
        <el-col>
          <el-dropdown @command="handleCommand">
            <span>操作
              <i class="el-icon-arrow-down" />
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="add">新增子部门</el-dropdown-item>
              <el-dropdown-item v-if="!isRoot" command="edit">编辑子部门</el-dropdown-item>
              <el-dropdown-item v-if="!isRoot" command="del">删除子部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { delDepartments } from '@/api/departments'

export default {
// props可以用数组来接收数据 也可以用对象来接收
// props: {   props属性: {  配置选项 }  }
  props: {
    treeNode: {
      type: Object,
      required: true
    },
    isRoot: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    handleCommand(com) {
      if (com === 'add') {
        this.$emit('addDepts', this.treeNode)
      } else if (com === 'edit') {
        this.$emit('editDepts', this.treeNode)
      } else {
        // 删除组织部门
        this.$confirm('您确定要删除该组织部门吗').then(() => {
          return delDepartments(this.treeNode.id)
        }).then(() => {
          this.$emit('delDeps')// 触发 自定义删除事件
          this.$message.success('删除组织部门成功')
        })
      }
    }
  }
}
</script>

<style>

</style>
